package com.example.controller;

import cn.hutool.core.lang.Dict;
import com.example.common.utils.R;
import com.example.entity.ImSingle;
import com.example.entity.User;
import com.example.service.ImSingleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述：单人聊天相关接口
 */
@RestController
@RequestMapping(value = "/imsingle")
@Api(tags = "单人聊天")
public class ImSingleController {

    @Autowired
    private ImSingleService imSingleService;

    @GetMapping("/findUser")
    @ApiOperation(value = "获取最近聊天用户", notes = "获取最近聊天用户")
    public R findUser(@RequestParam String FromUser) {
        List<User> list = imSingleService.findUser(FromUser);
        return R.success(list);
    }

    /**
     * 查询所有消息
     */
    @GetMapping
    @ApiOperation(value = "查询单人聊天消息", notes = "根据用户名查询单人聊天记录")
    public R findByFromUsername(@RequestParam String fromUser, @RequestParam String toUser) {
        List<ImSingle> all = imSingleService.findByUsername(fromUser, toUser);
        return R.success(all);
    }

    /**
     * 查询未读消息数量
     * @return 未读消息数量
     */
    @GetMapping("/unReadNums")
    @ApiOperation(value = "查询未读消息数量", notes = "查询指定用户的未读消息数量")
    public R findUnReadNums(@RequestParam String toUsername) {
        Dict dict = imSingleService.findUnReadNums(toUsername);
        return R.success(dict);
    }

}
